using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Finance.Web.Models.Mapping
{
    public class UserDepositMap : EntityTypeConfiguration<UserDeposit>
    {
        public UserDepositMap()
        {
            // Primary Key
            this.HasKey(t => new { UserCode = t.UserCode, DepCode = t.DepCode });

            // Properties
            this.Property(t => t.UserCode)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.DepCode)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("USER_DEPOSIT");
            this.Property(t => t.UserCode).HasColumnName("USERCODE");
            this.Property(t => t.DepCode).HasColumnName("DEPCODE");
            this.Property(t => t.Amount).HasColumnName("AMOUNT");
            this.Property(t => t.OpeningDate).HasColumnName("OPENINGDATE");
            this.Property(t => t.EndDate).HasColumnName("ENDDATE");

            // Relationships
            this.HasRequired(t => t.Deposit)
                .WithMany(t => t.UserDeposit)
                .HasForeignKey(d => d.DepCode);
            this.HasRequired(t => t.User)
                .WithMany(t => t.UserDeposit)
                .HasForeignKey(d => d.UserCode);

        }
    }
}
